package com.turtle.controller;

import com.turtle.dto.BlogParam;
import com.turtle.service.BlogService;
import com.turtle.valid.group.Update;
import com.turtle.vo.ResultBody;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotNull;

/**
 * @author lijiayu
 * @date 2020/7/20
 * @description 博客相关接口
 */
@RestController
@RequestMapping("/blog")
public class BlogController {

    @Autowired
    private BlogService blogService;

    @GetMapping("/list")
    public ResultBody list(){

        return ResultBody.result(null);
    }

    @PostMapping
    public ResultBody add(@RequestBody @Validated BlogParam param,@RequestAttribute Long userId){
        blogService.add(param,userId);
        return ResultBody.success();
    }

    @PutMapping
    public ResultBody update(@RequestBody @Validated({Update.class}) BlogParam param,@RequestAttribute Long userId){
        blogService.update(param,userId);
        return ResultBody.success();
    }

    @DeleteMapping
    public ResultBody delete(@RequestParam("id") Long id, @RequestAttribute Long userId){
        blogService.delete(id,userId);
        return ResultBody.success();
    }
}
